package com.twu.biblioteca;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: talkin
 * Date: 14-5-30
 * Time: 下午10:53
 * To change this template use File | Settings | File Templates.
 */
public class BibliotecaApp {

    public static void main(String[] args) {
        Biblioteca biblioteca = new Biblioteca();
        List<Book> books = new LinkedList<Book>();
        List<Movie> movies = new LinkedList<Movie>();

        boolean tag = true;

        String bookName;
        String movieName;
        String libraryNumber;
        String password;
        boolean login = false;

        biblioteca.welcomeMessage();

        biblioteca.addBook(new Book("book1", "author1", "2007"), books);
        biblioteca.addBook(new Book("book2", "author2", "2009"), books);
        biblioteca.addBook(new Book("book3", "author3", "2011"), books);

        biblioteca.addMovie(new Movie("movie1", "2012", "director1", "6"), movies);
        biblioteca.addMovie(new Movie("movie2", "2012", "director2", "6"), movies);
        biblioteca.addMovie(new Movie("movie3", "2012", "director3", "6"), movies);

        while (tag){
            System.out.println("\n-----------------------------------------");
            System.out.println("Main Menu:");

            if (login) {
                System.out.println(" @ User_information");
            }
            else {
                System.out.println(" @ Log_in");
            }

            System.out.println(" @ List_Books");
            System.out.println(" @ Checkout_Book");
            System.out.println(" @ Return_Book");
            System.out.println(" @ List_Movies");
            System.out.println(" @ Checkout_Movie");
            System.out.println(" @ Quit");
            System.out.println("-----------------------------------------");
            System.out.print("please input your option:");

            Scanner scanner = new Scanner(System.in);
            String input = scanner.next();

            if (input.equals("Quit")) {
                tag = false;
            } else if (input.equals("Log_in")) {
                System.out.print("library number :");
                libraryNumber = scanner.next();
                System.out.print("password :");
                password = scanner.next();
                login = biblioteca.logIn(libraryNumber, password);
                System.out.println("Log in successful!");
            } else if (input.equals("User_information")) {
                User user = new User("jing", "jing@gmail.com", "00001111");
                biblioteca.userInformation(user);
            } else if (input.equals("List_Books")) {
                biblioteca.getListOfBooks(books);
            } else if (input.equals("List_Movies")) {
                biblioteca.getListOfMovies(movies);
            } else if (input.equals("Checkout_Book")) {
                if (login) {
                    System.out.print("Please input the book's name :");
                    bookName = scanner.next();
                    biblioteca.checkOutBook(bookName, books);
                } else {
                    System.out.println("Please log in first!");
                    System.out.print("library number :");
                    libraryNumber = scanner.next();
                    System.out.print("password :");
                    password = scanner.next();
                    login = biblioteca.logIn(libraryNumber, password);
                    System.out.println("Log in successful! Please checkout again.");
                }
            } else if (input.equals("Return_Book")) {
                System.out.print("Please input the book's name :");
                bookName = scanner.next();
                biblioteca.returnBook(bookName, books);
            } else if (input.equals("Checkout_Movie")) {
                System.out.print("Please input the movie's name :");
                movieName = scanner.next();
                biblioteca.checkOutMovie(movieName, movies);
            }else {
                System.out.println("   ******   Select a valid option!   ******");
            }
        }
    }
}
